package com.audi.handler;

import java.util.ArrayList;

import com.audi.dto.MemberItem;

import android.os.Bundle;
import android.os.Message;
import android.util.Log;

/**
 * @author PhongNT11
 * 
 */
public class MemberHandler extends Handler  {

	public Message process(int actionId, String data) {
		Message message = new Message();
		Bundle dataBundle = new Bundle();
		message.arg1 = 0;
		String key = String.valueOf(actionId);
		try {
			switch (actionId) {
			case addMember:
				dataBundle.putInt(key, Integer.valueOf(data));
				break;
			case getListMember:
				dataBundle.putSerializable(key, convertJson2ListMember(data));
				break;
			case UPDATE_MEMBER:
			case DELETE_MEMBER:
				dataBundle.putInt(key, Integer.valueOf(data));
				break;
			case CHECK_MEMBER_EXIST:
				dataBundle.putBoolean(key, Boolean.valueOf(data));
				break;
			default:
				break;
			}
		} catch (Exception e) {
			Log.e("Client", "[MemberHandler.java]: " + e.toString());
			message.arg1 = -1;
		}
		message.setData(dataBundle);
		return message;
	}
	
	public ArrayList<MemberItem> convertJson2ListMember(String data) {
		ArrayList<MemberItem> result = (ArrayList<MemberItem>) convertJson2List(data, MemberItem.class);		
		return result;
	}
}
